//
//  ViewController.swift
//  searchComboxDemo
//
//  Created by 陆永权 on 15/9/2.
//  Copyright (c) 2015年 Xunilu. All rights reserved.
//

import UIKit
import searchCombox
class ViewController: UIViewController, UITableViewDataSource {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        dept.alwaysShow = true
        //dept.chooserBackgroundColor = UIColor.blueColor()
        dept.chooserBorderColor = UIColor.blueColor()  //UIColor(red: 50, green: 50, blue: 50, alpha: 1)
        dept.chooserSeparatorColor = UIColor.blueColor()
        dept.chooserBorderWidth = 1
        dept.dataSource = self
        dept.backgroundColor = UIColor.blackColor()
        let dept3 = searchCombox(frame: CGRect(x: 10, y: 350, width:200, height: 40))
        dept3.dataSource = self
        dept3.isAutoComplete = false
        let dept2 = searchCombox(frame: CGRect(x: 10, y: 300, width:200, height: 40))
        dept2.dataSource = self
        dept2.isShowSearchFirst = false
        //dept2.isMatchFunc = {(s0 : String,s1 : String) -> Bool in return s0 == s1}
        dept2.isMatchFunc = {(s1:String,s2:String) -> Bool in return s2.componentsSeparatedByString(s1).count > 1}
        //componentsSeparatedByString
        //dept2.backgroundColor = UIColor.blackColor()
        self.view.addSubview(dept2)
        self.view.addSubview(dept3)
        //dept.width =
        //dept.height = 400
        //dept.isShowSearchFirst = false
        //dept.chooserBackgroundColor = UIColor.blueColor()
        // Do any additional setup after loading the view, typically from a nib.
    }

    @IBOutlet weak var dept: searchCombox!
    //@IBOutlet weak var deptCombox: searchCombox!

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 2000
    }
    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        if let cellValue = tableView.dequeueReusableCellWithIdentifier("demo(\(indexPath.row),\(indexPath.section))") as? UITableViewCell {
            return cellValue
        }
        else
        {
        let cell = UITableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier: "demo(\(indexPath.row),\(indexPath.section))")
        //let label = UILabel(frame: CGRect(x: 1, y: 1, width: 50, height: 30))
        //label.font = UIFont(name: "System", size: 9)
        //label.text = "demo"
        //label.sizeToFit()
        //cell.textLabel!.textInputMode = UITextInputMode.dis
        //cell.textLabel!.
        cell.textLabel!.text = "Row(\(indexPath.row))"
        cell.textLabel!.backgroundColor = UIColor.clearColor()
        cell.layoutMargins = UIEdgeInsetsZero
        
        //cell.description = "SADF"
        
        //cell.addSubview(label)
        return cell
        }
    }
}

